﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using FATCASchema.Nodes;

namespace FATCATool
{
    public partial class FATCAContainer : UserControl
    {
        private FATCA_OECD _filing;

        public FATCAContainer()
        {
            InitializeComponent();
            DocAllControls();
        }

        public void Initialize(FATCA_OECD filing)
        {
            _filing = filing;
            fatcaTree.LoadTree(_filing);
        }

        private void fatcaTree_TreeNodeSelected(object sender, NodeSelectedEventArgs e)
        {            
            switch(e.Node.GetType().ToString())
            {
                case "FATCASchema.Nodes.AccountReportNode":
                    if (e.Node.NodeObject == null || !(e.Node.NodeObject is CorrectableAccountReport_Type))
                        return;

                    accountReportControl.Initialize((CorrectableAccountReport_Type)e.Node.NodeObject);
                    HideAllControls();
                    accountReportControl.Visible = true;
                    break;
                case "FATCASchema.Nodes.CorrectableOrganisationParty":
                    if (e.Node.NodeObject == null || !(e.Node.NodeObject is CorrectableOrganisationParty_Type))
                        return;

                    correctableOganizationControl.Intitalize((CorrectableOrganisationParty_Type)e.Node.NodeObject);
                    HideAllControls();
                    correctableOganizationControl.Visible = true;
                    break;
                //case "FATCASchema.Nodes.FATCA_OECDNode":
                //    break;
                //case "FATCASchema.Nodes.FATCANode":
                //    break;
                case "FATCASchema.Nodes.MessageSpecNode":
                    if (e.Node.NodeObject == null || !(e.Node.NodeObject is MessageSpec_Type))
                        return;

                    messageSpecControl.Intitalize((MessageSpec_Type)e.Node.NodeObject);
                    HideAllControls();
                    messageSpecControl.Visible = true;
                    break;
                case "FATCASchema.Nodes.PoolReportNode":
                    if (e.Node.NodeObject == null || !(e.Node.NodeObject is CorrectablePoolReport_Type))
                        return;

                    poolReportControl.Intitalize((CorrectablePoolReport_Type)e.Node.NodeObject, e.TNode);
                    HideAllControls();
                    poolReportControl.Visible = true;
                    break;
                //case "FATCASchema.Nodes.ReportingGroupNode":
                //    break;
            }
        }

        private void DocAllControls()
        {
            messageSpecControl.Dock = DockStyle.Fill;
            correctableOganizationControl.Dock = DockStyle.Fill;
            poolReportControl.Dock = DockStyle.Fill;
            accountReportControl.Dock = DockStyle.Fill;
        }

        private void HideAllControls()
        {
            messageSpecControl.Visible = false;
            correctableOganizationControl.Visible = false;
            poolReportControl.Visible = false;
            accountReportControl.Visible = false;
        }
    }
}
